import React, { createRef, PureComponent } from 'react'

export default class App extends PureComponent {
  constructor(props) {
    super(props)

    this.state = {
    }

    this.usernameRef = createRef()
  }

  render() {
    return (
      <div>
        {/* 受控组件 */}
        <form onSubmit={e => this.handleSubmit(e)}>
          <label htmlFor="username">
            用户：
            <input type="text" id="username" ref={this.usernameRef}/>
          </label>
          <input type="submit" value="提交" />
        </form>
      </div>
    )
  }

  handleSubmit(event) {
    event.preventDefault()
    console.log(this.usernameRef.current.value)
  }
}

